package com.hxkcloud.patient.activitys;

import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.recorder.MediaManger;

/**
 * Created by william_sun on 2016-07-15.
 * Description:展示录音結果界面
 */
public class RecorderActivity extends BaseActivity implements View.OnClickListener {
    //title
    private LinearLayout ll_title;
    private ImageView iv_back;
    private TextView tv_title;
    private TextView tv_del;

    private ImageView iv_play;

    private String path;

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {

        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recorder);

        path = this.getIntent().getStringExtra("path");
        initView();
    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
        iv_back = (ImageView) findViewById(R.id.iv_title_back);
        tv_title = (TextView) findViewById(R.id.tv_title_title);
        tv_del = (TextView) findViewById(R.id.tv_title_func);

        iv_play = (ImageView) findViewById(R.id.iv_recorder);

        setTitlePadding(ll_title);
        iv_back.setVisibility(View.VISIBLE);
        tv_title.setText(getResources().getText(R.string.voice_recorder));
        iv_back.setOnClickListener(this);
        tv_del.setVisibility(View.VISIBLE);
        tv_del.setText(R.string.delete);
        tv_del.setOnClickListener(this);

        iv_play.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_title_back:
                finish();
                break;
            case R.id.tv_title_func:
                Intent iBack = new Intent(mContext, AddInspectionReportActivity.class);
                iBack.putExtra("del", true);
                setResult(RESULT_OK, iBack);
                finish();
                break;
            case R.id.iv_recorder:
                if (!TextUtils.isEmpty(path)) {
                    if (!MediaManger.isPlaying()) {
                        MediaManger.playSound(path, new MediaPlayer.OnCompletionListener() {
                            @Override
                            public void onCompletion(MediaPlayer mp) {

                            }
                        });
                    }
                } else {
                    toastMsg(R.string.filewrong);
                }
                break;
        }
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }


}
